<?php
/**
 * Created by Zend Studio.
 * User: FDG348
 * @param  FDG348 2018-03-23  553 【后台需求】用户在心愿单界面预约到店后，后台可查看用户预约到店时心愿单商品
 * Date: 2018/03/23
 * Time: 10:57
 */
namespace backend\models;

use yii\db\ActiveRecord;

class ShareWishReservLog extends ActiveRecord{
    public static function tableName(){
        return '{{%share_wish_reserv_log}}';
    }
    
    const TYPE_RECORD    =1;//联系记录
    const TYPE_LOG       =2;//操作日志
    
    const LOG_TYPE_CREATE       =1;//客户提交预约门店
    const LOG_TYPE_USE_FLG      =2;//修改处理状态
    const LOG_TYPE_EXPORT_EXCEL =3;//导出excel

	/**
	 * @获取创建人
	 */
	public function getCreator(){
	    $userInfo = \common\helps\tools::getloginUserInfo();
	    if($userInfo){
	        $userName = $userInfo->userName;
	    }else{
	        $userName = '';
	    }
	    return $userName;
	}
	
	/**
	 * @获取创建人
	 */
	public function getLogWriter(){
	    $userInfo = \common\helps\tools::getloginUserInfo();
	    if($userInfo->userId){
	        $user = UserMaster::find()->select('user_name,true_name')->where('id='.$userInfo->userId)->asArray()->one();
	        $userName = $user['user_name'].' '.$user['true_name'];
	    }else{
	        $userName = '';
	    }
	    return $userName;
	}
	
	/**
	 * 后台预约到店操作日志
	 */
	public function writeWishSingleReportLog($wish_single_report_id,$type,$log_type='',$use_flg='',$record=''){
	    $write_log = new ShareWishReservLog();
	    $write_log->share_wish_reserv_id = $wish_single_report_id;
	    $write_log->type = $type;
	    $write_log->log_type = $log_type;
	    $write_log->record = $record;
	    switch ($log_type){
// 	        case 1:
// 	            $write_log->content = '客户提交预约门店';
// 	            break;
	        case 2:
	            $write_log->content = $use_flg == 1 ? '勾选了处理' : '去除了处理勾选';
	            break;
	        case 3:
	            $write_log->content = '导出excel';
	            break;
	    }
	    $write_log->oper = $this::getLogWriter();
	    $write_log->oper_time = date('Y-m-d H:i:s');
	    $write_log->save();
	    $id = $write_log->attributes['id'];
	    if (!$id){
	        return false;
	    }
	    return true;
	}
}